/**
 * This file was exported using ldfparser Python package
 */
LIN_description_file;
LIN_protocol_version = "{{ ldf.get_protocol_version() }}";
LIN_language_version = "{{ ldf.get_language_version() }}";
LIN_speed = {{ (ldf.get_baudrate() / 1000.0) | float }} kbps;
{%- if ldf.get_channel() %}
Channel_name = "{{ ldf.get_channel() }}";
{%- endif %}

Nodes {
    {%- if ldf.get_master() %}
    Master: {{ ldf.get_master().name }}, {{ ldf.get_master().timebase * 1000 | float}} ms, {{ ldf.get_master().jitter * 1000 }} ms{%- if ldf.get_master().max_header_length is not none %}, {{ldf.get_master().max_header_length}} bits{%- endif %}{%- if ldf.get_master().response_tolerance is not none %}, {{ldf.get_master().response_tolerance * 100}} %{%- endif %};
    {%- endif %}
    {%- if ldf.get_slaves() %}
    Slaves: {%- for slave in ldf.get_slaves() %} {{ slave.name }}{%- if not loop.last %},{% endif -%}{%- endfor -%};
    {%- endif %}
}

{%- if ldf.get_language_version().major == 2 or "Iso17987Version" in ldf.get_language_version().__class__.__name__ or "J2602" in ldf.get_language_version().__class__.__name__ %}
Node_attributes {
    {%- for slave in ldf.get_slaves() %}
    {{slave.name}} {
        LIN_protocol = "{{slave.lin_protocol}}";
        configured_NAD = {{slave.configured_nad}};
        initial_NAD = {{slave.initial_nad}};
        {%- if slave.product_id %}
        product_id = {{slave.product_id.supplier_id}}, {{slave.product_id.function_id -}}
        {%- if slave.product_id.variant -%}
        , {{slave.product_id.variant -}}
        {%- endif %};
        {%- endif %}
        {%- if slave.response_error %}
        response_error = {{slave.response_error.name}};
        {%- endif %}
        P2_min = {{slave.p2_min * 1000}} ms;
        ST_min = {{slave.st_min * 1000}} ms;
        N_As_timeout = {{slave.n_as_timeout * 1000}} ms;
        N_Cr_timeout = {{slave.n_cr_timeout * 1000}} ms;
        {%- if slave.configurable_frames.items() | length > 0 %}
        configurable_frames {
            {%- for (id, frame) in slave.configurable_frames.items() %}
            {{frame.name}}{% if slave.lin_protocol == "2.0" %} = {{id}}{% endif -%};
            {%- endfor %}
        }
        {%- endif %}
        {%- if slave.response_tolerance %}
        response_tolerance = {{slave.response_tolerance * 100}} %;
        {%- endif %}
    }
    {%- endfor %}
}
{%- endif %}

Signals {
    {%- for signal in ldf.get_signals() %}
    {{signal.name}}: {{signal.width}},
    {%- if signal.is_array() %} {
    {%- for value in signal.init_value -%}
    {{value}} {%- if not loop.last %},{% endif -%}
    {%- endfor %} }
    {%- else %} {{signal.init_value}}
    {%- endif -%}, {{ signal.publisher.name -}}
    {%- for subscriber in signal.subscribers %}, {{ subscriber.name }}
    {%- endfor -%};
    {%- endfor %}
}

Frames {
    {%- for frame in ldf.get_unconditional_frames() %}
    {{frame.name}}: {{frame.frame_id}}, {{frame.publisher.name}}, {{frame.length}} {
    {%- for signal in frame.signal_map %}
        {{signal[1].name}}, {{signal[0]}};
    {%- endfor %}
    }
    {%- endfor %}
}

{%- if ldf.get_event_triggered_frames() | length > 0 %}
Event_triggered_frames {
    {%- for frame in ldf.get_event_triggered_frames() %}
    {{frame.name}}: {{frame.collision_resolving_schedule_table.name}}, {{frame.frame_id}}, 
    {%- for unconditional in frame.frames -%}
        {{unconditional.name}}{%- if not loop.last %}, {% endif -%}
    {%- endfor -%};
    {%- endfor %}
}
{%- endif %}

{%- if ldf.get_sporadic_frames() | length > 0 %}
Sporadic_frames {
    {%- for frame in ldf.get_sporadic_frames() %}
    {{frame.name}}: 
    {%- for unconditional in frame.frames -%}
        {{unconditional.name}}{%- if not loop.last %}, {% endif -%}
    {%- endfor -%};
    {%- endfor %}
}
{%- endif %}

Schedule_tables {
    {%- for table in ldf.get_schedule_tables() %}
    {{table.name}} {
        {%- for entry in table.schedule %}
        {%- if entry.__class__.__name__ == 'LinFrameEntry' %}
        {{ entry.frame.name }} delay {{entry.delay * 1000}} ms;
        {%- elif entry.__class__.__name__ == 'MasterRequestEntry' %}
        MasterReq delay {{entry.delay * 1000}} ms;
        {%- elif entry.__class__.__name__ == 'SlaveResponseEntry' %}
        SlaveResp delay {{entry.delay * 1000}} ms;
        {%- elif entry.__class__.__name__ == 'AssignNadEntry' %}
        AssignNAD { {{ entry.node.name }} } delay {{entry.delay * 1000}} ms;
        {%- elif entry.__class__.__name__ == 'AssignFrameIdRangeEntry' %}
        AssignFrameIdRange { {{ entry.node.name }}, {{entry.frame_index}}
        {%- if entry.pids | length > 0 -%}
        , {{entry.pids[0]}}, {{entry.pids[1]}}, {{entry.pids[2]}}, {{entry.pids[3]}}
        {%- endif -%}
        } delay {{entry.delay * 1000}} ms;
        {%- elif entry.__class__.__name__ == 'ConditionalChangeNadEntry' %}
        ConditionalChangeNAD { {{entry.nad}}, {{entry.id}}, {{entry.byte}}, {{entry.mask}}, {{entry.inv}}, {{entry.new_nad}} } delay {{entry.delay * 1000}} ms;
        {%- elif entry.__class__.__name__ == 'DataDumpEntry' %}
        DataDump { {{ entry.node.name }}, {{entry.data[0]}}, {{entry.data[1]}}, {{entry.data[2]}}, {{entry.data[3]}}, {{entry.data[4]}} } delay {{entry.delay * 1000}} ms;
        {%- elif entry.__class__.__name__ == 'SaveConfigurationEntry' %}
        SaveConfiguration { {{ entry.node.name }} } delay {{entry.delay * 1000}} ms;
        {%- elif entry.__class__.__name__ == 'AssignFrameIdEntry' %}
        AssignFrameId { {{ entry.node.name }}, {{entry.frame.name}} } delay {{entry.delay * 1000}} ms;
        {%- elif entry.__class__.__name__ == 'UnassignFrameIdEntry' %}
        UnassignFrameId { {{ entry.node.name }}, {{entry.frame.name}} } delay {{entry.delay * 1000}} ms;
        {%- elif entry.__class__.__name__ == 'FreeFormatEntry' %}
        FreeFormat { {{entry.data[0]}}, {{entry.data[1]}}, {{entry.data[2]}}, {{entry.data[3]}}, {{entry.data[4]}}, {{entry.data[5]}}, {{entry.data[6]}}, {{entry.data[7]}} } delay {{entry.delay * 1000}} ms;
        {%- endif %}
        {%- endfor %}
    }
    {%- endfor %}
}

{%- if ldf.get_signal_encoding_types() | length > 0 %}
Signal_encoding_types {
    {%- for encoder in ldf.get_signal_encoding_types() %}
    {{encoder.name}} {
        {%- for converter in encoder.get_converters() %}
        {%- if converter.__class__.__name__ == 'LogicalValue' %}
        logical_value, {{converter.phy_value}}
        {%- if converter.info -%}
        , "{{converter.info}}"
        {%- endif -%}
        ;
        {%- elif converter.__class__.__name__ == 'PhysicalValue' %}
        physical_value, {{converter.phy_min}}, {{converter.phy_max}}, {{converter.scale}}, {{converter.offset}}
        {%- if converter.unit -%}
        , "{{converter.unit}}"
        {%- endif -%}
        ;
        {%- elif converter.__class__.__name__ == 'BCDValue' %}
        bcd_value;
        {%- elif converter.__class__.__name__ == 'ASCIIValue' %}
        ascii_value;
        {%- endif %}
        {%- endfor %}
    }
    {%- endfor %}
}

Signal_representation {
    {%- for encoder in ldf.get_signal_encoding_types() %}
    {%- if encoder.get_signals() | length > 0 %}
    {{encoder.name}}: {% for signal in encoder.get_signals() -%}
    {{signal.name}}{%- if not loop.last %}, {% endif -%}
    {%- endfor -%}
    ;
    {%- endif %}
    {%- endfor %}
}
{%- endif %}